﻿
using System;
using System.Collections;
using System.Web.UI.WebControls;

namespace GiftNet.Model
{
	#region FactoryOrderItems Model -(by fangyifeng at 2013/12/23 18:42:00)

	/// <summary>
	/// FactoryOrderItems object'FactoryOrderItems'.
	/// </summary>
    [Serializable]
	public class FactoryOrderItems : System.IComparable
		{
		#region Member Variables
		
		protected Guid _id;
		protected decimal _quantity;
        protected decimal _ManualQuantity;
        protected decimal _QuantityAll;
		protected decimal _price;
		protected decimal _stockIn;
		protected bool _isAllStockIn;
        protected string _stockInDesc;
        protected string _stockInDescTemp;
		protected short _orderItemStatus;
		protected string _remark;
		protected string _operatingPC;
		protected bool _isActivate;
        protected bool _IsDel;
        protected bool _IsMyOrder;
		protected Factory _factory;
		protected FactoryOrder _factoryOrder;
        protected FactoryPrice _factoryPrice;
        protected ProOrderPublic _ProOrderPublic;
        protected decimal _moveinqty;
        protected decimal _AdjustPrice=0;
        protected bool _IsUpdateQty=false;
		
		protected static String _sortExpression = "Id";
		protected static SortDirection _sortDirection = SortDirection.Ascending;

		#endregion

		#region Constructors

		public FactoryOrderItems() { }

        public FactoryOrderItems(decimal quantity, decimal price, decimal stockIn, bool isAllStockIn, string stockInDesc, short orderItemStatus, string remark, string operatingPC, bool isActivate, Factory factory, FactoryOrder factoryOrder, FactoryPrice factoryPrice, decimal adjustPrice, bool isUpdateQty, decimal moveinqty)
        {
            _moveinqty = moveinqty;
            _AdjustPrice = adjustPrice;
            _IsUpdateQty = isUpdateQty;
            this._quantity = quantity;
            this._price = price;
            this._stockIn = stockIn;
            this._isAllStockIn = isAllStockIn;
            this._stockInDesc = stockInDesc;
            this._orderItemStatus = orderItemStatus;
            this._remark = remark;
            this._operatingPC = operatingPC;
            this._isActivate = isActivate;
            this._factory = factory;
            this._factoryOrder = factoryOrder;
            this._factoryPrice = factoryPrice;
        }

		#endregion

		#region Public Properties
        public virtual decimal MoveInQty
        {
            get { return _moveinqty; }
            set { _moveinqty = value; }
        }

        public virtual decimal AdjustPrice
        {
            get { return _AdjustPrice; }
            set { _AdjustPrice = value; }
        }

        public virtual bool IsUpdateQty
        {
            get { return _IsUpdateQty; }
            set { _IsUpdateQty = value; }
        }

        /// <summary>
        /// 最后价格。根据系统报价和优惠报价综合考虑而定
        /// </summary>
        public virtual decimal FinalPrice
        {
            get
            {
                if (_price <= (decimal)0)
                    return _price;
                else if (_AdjustPrice > (decimal)0)
                    return _AdjustPrice;
                else
                    return _price;
            }
        }

        /// <summary>
        /// 最后价格。根据系统报价和优惠报价综合考虑而定
        /// </summary>
        public virtual string FinalPriceString
        {
            get
            {
                if (_AdjustPrice <= 0)
                    return String.Empty;
                else
                    return decimal.Round(_AdjustPrice, 2).ToString();
            }
        }

		public virtual Guid Id
		{
			get {return _id;}
			set {_id = value;}
		}

		public virtual decimal Quantity
		{
			get { return _quantity; }
			set { _quantity = value; }
		}
        public virtual decimal ManualQuantity
		{
            get { return _ManualQuantity; }
            set { _ManualQuantity = value; }
		}
        public virtual decimal QuantityAll
		{
            get { return _QuantityAll; }
            set { _QuantityAll = value; }
		}
        
		public virtual decimal Price
		{
			get { return _price; }
			set { _price = value; }
		}

		public virtual decimal StockIn
		{
			get { return _stockIn; }
			set { _stockIn = value; }
		}

		public virtual bool IsAllStockIn
		{
			get { return _isAllStockIn; }
			set { _isAllStockIn = value; }
		}

		public virtual string StockInDesc
		{
			get { return _stockInDesc; }
			set
			{
				if ( value != null && value.Length > 100)
					throw new ArgumentOutOfRangeException("Invalid value for StockInDesc", value, value.ToString());
				_stockInDesc = value;
			}
		}

        public virtual string StockInDescTemp
        {
            get { return _stockInDescTemp; }
            set
            {
                if (value != null && value.Length > 500)
                    throw new ArgumentOutOfRangeException("Invalid value for StockInDesc", value, value.ToString());
                _stockInDescTemp = value;
            }
        }
		public virtual short OrderItemStatus
		{
			get { return _orderItemStatus; }
			set { _orderItemStatus = value; }
		}

		public virtual string Remark
		{
			get { return _remark; }
			set
			{
				if ( value != null && value.Length > 250)
					throw new ArgumentOutOfRangeException("Invalid value for Remark", value, value.ToString());
				_remark = value;
			}
		}

		public virtual string OperatingPC
		{
			get { return _operatingPC; }
			set
			{
				if ( value != null && value.Length > 32)
					throw new ArgumentOutOfRangeException("Invalid value for OperatingPC", value, value.ToString());
				_operatingPC = value;
			}
		}

		public virtual bool IsActivate
		{
			get { return _isActivate; }
			set { _isActivate = value; }
		}
        public virtual bool IsDel
		{
            get { return _IsDel; }
            set { _IsDel = value; }
		}

        public virtual bool IsMyOrder
		{
            get { return _IsMyOrder; }
            set { _IsMyOrder = value; }
		}
        
		public virtual Factory Factory
		{
			get { return _factory; }
			set { _factory = value; }
		}

		
		public virtual FactoryOrder FactoryOrder
		{
			get { return _factoryOrder; }
			set { _factoryOrder = value; }
		}

		
		public virtual FactoryPrice FactoryPrice
		{
			get { return _factoryPrice; }
			set { _factoryPrice = value; }
        }

        public virtual ProOrderPublic ProOrderPublic
        {
            get { return _ProOrderPublic; }
            set { _ProOrderPublic = value; }
        }

		
        public static String SortExpression
        {
            get { return _sortExpression; }
            set { _sortExpression = value; }
        }

        public static SortDirection SortDirection
        {
            get { return _sortDirection; }
            set { _sortDirection = value; }
        }
		#endregion
		
        #region IComparable Methods
        public virtual int CompareTo(object obj)
        {
			if (!(obj is FactoryOrderItems))
				throw new InvalidCastException("This object is not of type FactoryOrderItems");
			
			int relativeValue;
			switch (SortExpression)
			{
				case "Id":
					relativeValue = this.Id.CompareTo(((FactoryOrderItems)obj).Id);
					break;
				case "Quantity":
                    relativeValue = this.Quantity.CompareTo(((FactoryOrderItems)obj).Quantity);
					break;
				case "Price":
					relativeValue = this.Price.CompareTo(((FactoryOrderItems)obj).Price);
					break;
				case "StockIn":
					relativeValue = (this.StockIn != null) ? this.StockIn.CompareTo(((FactoryOrderItems)obj).StockIn) : -1;
					break;
				case "IsAllStockIn":
					relativeValue = (this.IsAllStockIn != null) ? this.IsAllStockIn.CompareTo(((FactoryOrderItems)obj).IsAllStockIn) : -1;
					break;
				case "StockInDesc":
					relativeValue = (this.StockInDesc != null) ? this.StockInDesc.CompareTo(((FactoryOrderItems)obj).StockInDesc) : -1;
					break;
				case "OrderItemStatus":
					relativeValue = this.OrderItemStatus.CompareTo(((FactoryOrderItems)obj).OrderItemStatus);
					break;
				case "Remark":
					relativeValue = (this.Remark != null) ? this.Remark.CompareTo(((FactoryOrderItems)obj).Remark) : -1;
					break;
				case "OperatingPC":
					relativeValue = (this.OperatingPC != null) ? this.OperatingPC.CompareTo(((FactoryOrderItems)obj).OperatingPC) : -1;
					break;
				case "IsActivate":
					relativeValue = this.IsActivate.CompareTo(((FactoryOrderItems)obj).IsActivate);
					break;
                default:
                    goto case "Id";
			}
            if (FactoryOrderItems.SortDirection == SortDirection.Ascending)
				relativeValue *= -1;
			return relativeValue;
		}
		#endregion
	}

	#endregion
}
